package com.gzgs.dao;

import com.gzgs.domain.Member;
import com.gzgs.domain.Orders;
import com.gzgs.domain.Product;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;


import java.util.List;

/**
 * 订单持久层接口
 */

@Repository
public interface OrdersDao {


    /**
     * 查询所有
     */
    @Select("select * from orders")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "productId",property = "product",one = @One(select =
                    "com.gzgs.dao.ProductDao.findById"))
    })
    public List<Orders> findAll() throws Exception;

    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @Select("select * from orders where id=#{id}")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "memberId",javaType = Member.class,property = "member",one = @One(select =
                    "com.gzgs.dao.MemberDao.findById")),
            @Result(column = "productId",javaType = Product.class,property = "product",one = @One(select = "com.gzgs.dao.ProductDao.findById")),
            @Result(column = "id",javaType =java.util.List.class,property = "travellers",many = @Many(select = "com.gzgs.dao.TravellerDao.findByOrdersId"))

    })
    public Orders findById(String id);

    /**
     * 删除订单信息
     * @param id
     */
    @Delete("delete from orders where productId=#{id}")
    void deleteByProductId(String id)throws Exception;
}
